﻿using System;
using System.Diagnostics;
using System.Text;

namespace Plugins.Samples
{
    using Interfaces;
    using Internal;

    class Program
    {
        static void Main(string[] args)
        {
            Stopwatch sw1 = new Stopwatch();
            StringBuilder sb1 = new StringBuilder();

            sw1.Start();
            sb1.Append(PiAlgorithm.Calculate(0, 10000));
            sw1.Stop();

            Console.WriteLine("Sequential: {0}", sw1.Elapsed);

            IPluginWorkItem wi = PiWorkItemManager.Create(10000);
            
            Stopwatch sw2 = new Stopwatch();
            sw2.Start();
            wi.Run();
            sw2.Stop();

            StringBuilder sb2 = new StringBuilder();
            Console.WriteLine("Parallel: {0}", sw2.Elapsed);

            Console.WriteLine("Ratio: {0}", (sw1.Elapsed.Ticks / sw2.Elapsed.Ticks));
            foreach (IWorkItemData item in PiWorkItemManager.Data)
            {
                sb2.Append(item.Result);
            }

            Debug.Assert(string.Equals(sb1.ToString(), sb2.ToString()));
            Console.ReadLine();
        }
    }
}
